﻿using UnityEngine;
using System.Collections;

public class DrugTrigger : MonoBehaviour {

	public float rotationSpeed;
	public float triggerThreshold;

	private void Update () {
		transform.Rotate(Vector3.up, rotationSpeed * Time.deltaTime);

		if(ChainJam.GetButtonJustPressed(ChainJam.BUTTON.A)
		   && Mathf.Abs((Player.Instance.transform.position - transform.position).magnitude) < triggerThreshold)
			TakeDrug();
	}

	private void TakeDrug()
	{
		Player.Instance.TakeDrug(name);

		foreach(DrugBehaviour db in GetComponents<DrugBehaviour>())
			db.OnTakeDrug();

		Debug.Log(name + " taken");
		Destroy(gameObject);
	}
}
